<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>线索管理</title>
    <link rel="shortcut icon" type="image/x-icon" href="../../favicon.ico" />
    <link rel="stylesheet" href="../../component/pear/css/pear.css">
    <script src="../../js/myUtils.js"></script>

</head>

<body class="pear-container">

    <div class="layui-card">
        <div class="layui-card-body" style="padding-bottom: 15px;">
            <div class="layui-collapse">
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">显示搜索栏<i class="layui-icon layui-colla-icon"></i></h2>
                    <fieldset class="table-search-fieldset layui-colla-content">
                        <!-- <legend class="legend-style">搜索栏</legend> -->
                        <form class="layui-form" id="formView">
                            <script id="formHtml" type="text/html">
                            <div class="layui-form-item">
                                <div id="addressDiv">
                                    <label class="layui-form-label">涉及区域</label>
                                    <div class="layui-input-inline">
                                        <select name="province" lay-filter="province" id="province">
                                            <option></option>
                                        </select>
                                    </div>
                                    <div class="layui-input-inline">
                                        <select name="city" lay-filter="city" id="city">
                                            <option></option>
                                        </select>
                                    </div>
                                    <div class="layui-input-inline">
                                        <select name="area" lay-filter="area" id="area">
                                            <option></option>
                                        </select>
                                    </div>
                                </div>
                                <label class="layui-form-label">开始时间</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="startTime" id="startTime" lay-verify="date"
                                        placeholder="例如:2021-01-01" autocomplete="off" class="layui-input">
                                </div>

                                <label class="layui-form-label">截止时间</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="endTime" id="endTime" lay-verify="date"
                                        placeholder="例如:2021-01-01" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label for="no" class="layui-form-label">受理编号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="no" autocomplete="off" id="no" class="layui-input">
                                </div>

                                <label class="layui-form-label" style="width: auto;">涉案类别</label>
                                <div class="layui-input-inline">
                                    <select name="reportCaseType" id="reportCaseType">
                                        {{# layui.each(d.options.reportCaseType, function(index, item){ }}
                                            <option value={{item.value}}>{{item.label}}</option>
                                        {{# }); }}
                                    </select>
                                </div>

                                <label class="layui-form-label" style="width: auto;">顽瘴痼疾类别</label>
                                <div class="layui-input-inline">
                                    <select name="issueType" id="issueType">
                                        {{# layui.each(d.options.issueType, function(index, item){ }}
                                            <option value={{item.value}}>{{item.label}}</option>
                                        {{# }); }}
                                    </select>
                                </div>

                                <label class="layui-form-label" style='width: auto;'>一手来源单位</label>
                                <div class="layui-input-inline">
                                    <select name="reportFrom" id="reportFrom" lay-filter="reportFrom">
                                        {{# layui.each(d.options.reportFrom, function(index, item){ }}
                                            <option value={{item.value}}>{{item.label}}</option>
                                        {{# }); }}
                                    </select>
                                </div>

                                <div id='reportFromDIV'>
                                    <label class="layui-form-label"></span>线索来源</label>
                                    <div class="layui-input-inline">
                                        <select name="reportType" id="reportType" lay-search="">
                                            {{# layui.each(d.options.reportType, function(index, item){ }}
                                                <option value={{item.value}}>{{item.label}}</option>
                                            {{# }); }}
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label for="name" class="layui-form-label">举报人</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="name" autocomplete="off" id="name" class="layui-input">
                                </div>

		                        <label for="phone" class="layui-form-label">举报人电话</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="phone" autocomplete="off" id="phone" class="layui-input">
                                </div>
                            
                                <label for="conclusion" class="layui-form-label">是否重复</label>
                                <div class="layui-input-inline">
                                    <select name="isRepeat" id="isRepeat">
                                        {{# layui.each(d.options.isRepeat, function(index, item){ }}
                                            <option value={{item.value}}>{{item.label}}</option>
                                        {{# }); }}
                                    </select>
                                </div>

                                <label for="conclusion" class="layui-form-label">多头举报</label>
                                <div class="layui-input-inline">
                                    <select name="multiSources" id="multiSources">
                                        <!-- <option value="-1">请选择</option> -->
                                        <option value="0">全部</option>
                                        <option value="1">属于多头</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="blackName" class="layui-form-label">被举报人</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="blackName" autocomplete="off" id="blackName"
                                        class="layui-input">
                                </div>
                                <div id="department">
                                    <label for="blackDepartment" class="layui-form-label"
                                        style="width: auto;">被举报人单位</label>
                                    <div class="layui-input-inline">
                                        <select name="blackDepartment">
                                            {{# layui.each(d.options.blackDepartment, function(index, item){ }}
                                                <option value={{item.value}}>{{item.label}}</option>
                                            {{# }); }}
                                        </select>
                                    </div>
                                </div>
                                <label for="isSend" class="layui-form-label">是否移送</label>
                                <div class="layui-input-inline">
                                    <select name="isSend" id="isSend">
                                        <option value="-1">请选择</option>
                                        <option value="0">否</option>
                                        <option value="1">是</option>
                                    </select>
                                </div>
                                <label class="layui-form-label" style="width: auto;">被举报人涉案类别</label>
                                <div class="layui-input-inline">
                                    <select name="caseType" id="caseType">
                                        {{# layui.each(d.options.caseType, function(index, item){ }}
                                            <option value={{item.value}}>{{item.label}}</option>
                                        {{# }); }}
                                    </select>
                                </div>
                            </div>

                            <div class="layui-form-item">

                                <label for="sendToId" class="layui-form-label">移送编号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="sendToId" autocomplete="off" id="sendToId" class="layui-input">
                                </div>

                                <label class="layui-form-label">移送单位</label>
                                <div class="layui-input-inline">
                                    <select name="sendDepartment" id="sendDepartment" lay-filter="sendDepartment">
                                        {{# layui.each(d.options.sendDepartment, function(index, item){ }}
                                            <option value={{item.value}}>{{item.label}}</option>
                                        {{# }); }}
                                    </select>
                                </div>

                                {{#  if(d.pageType == undefined){ }}
                                <label class="layui-form-label">线索状态</label>
                                <div class="layui-input-inline">
                                    <select name="reportState" id="reportState" lay-filter="reportState">
                                        {{# layui.each(d.options.reportState, function(index, item){ }}
                                            <option value={{item.value}}>{{item.label}}</option>
                                        {{# }); }}
                                    </select>
                                </div>
                                {{#  } }}

                                <label for="progress" class="layui-form-label">核查进展</label>
                                <div class="layui-input-inline">
                                    <select name="progress" id="progress">
                                        {{# layui.each(d.options.progress, function(index, item){ }}
                                            <option value={{item.value}}>{{item.label}}</option>
                                        {{# }); }}
                                    </select>
                                </div>
                            </div>
                                
                            <div class="layui-form-item">
                                <label for="level" class="layui-form-label">核查等级</label>
                                <div class="layui-input-inline">
                                    <select name="level" id="level">
                                        {{# layui.each(d.options.level, function(index, item){ }}
                                            <option value={{item.value}}>{{item.label}}</option>
                                        {{# }); }}
                                    </select>
                                </div>
                                
                                <label for="conclusion" class="layui-form-label">核查结论</label>
                                <div class="layui-input-inline">
                                    <select name="conclusion" id="conclusion">
                                        {{# layui.each(d.options.conclusion, function(index, item){ }}
                                            <option value={{item.value}}>{{item.label}}</option>
                                        {{# }); }}
                                    </select>
                                </div>

                                <label class="layui-form-label">四种形态</label>
                                <div class="layui-input-inline">
                                    <select name="fourShapes" id="fourShapes">
                                        {{# layui.each(d.options.fourShapes, function(index, item){ }}
                                            <option value={{item.value}}>{{item.label}}</option>
                                        {{# }); }}
                                    </select>
                                </div>

                                <label class="layui-form-label">处理结果</label>
                                <div class="layui-input-inline">
                                    <select name="processResult" id="processResult">
                                        {{# layui.each(d.options.processResult, function(index, item){ }}
                                            <option value={{item.value}}>{{item.label}}</option>
                                        {{# }); }}
                                    </select>
                                </div>

                                <button type="button" class="pear-btn pear-btn-md pear-btn-primary" lay-submit="" lay-filter="search">
                                    <i class="layui-icon layui-icon-search"></i>
                                    查询
                                </button>
                                <button type="reset" class="pear-btn pear-btn-md" lay-filter="reset">
                                    <i class="layui-icon layui-icon-refresh"></i>
                                    重置
                                </button>
                            </div>
                        </script>
                        </form>
                    </fieldset>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="excel-table" lay-filter="excel-table"></table>
        </div>
    </div>


    <script type="text/html" id="involvedRegionTpl">
        {{# layui.each(d.involvedRegion, function(index, item){ }}
            <div class="layui-input-inline">
                {{#  if(item.province != null){ }}
                    {{#  if(item.city != null){ }}
                        {{#  if(item.area != null){ }}
                            {{item.province}}{{item.city}}{{item.area}}
                        {{#  } else { }}
                            {{item.province}}{{item.city}}
                        {{#  } }}
                    {{#  } else { }}
                        {{item.province}}
                    {{#  } }}
                {{#  } }}
            </div>
        {{# }); }}
    </script>

    <script type="text/html" id="blackNameTpl">
        {{# layui.each(d.reporteders, function(index, item){ }}
        <div class="layui-input-inline">{{item.name}}</div>
        {{# }); }}
    </script>

    <script type="text/html" id="blackCardIdTpl">
        {{# layui.each(d.reporteders, function(index, item){ }}
        {{#  if(item.blackCardId != ''){ }}
        <div class="layui-input-inline">{{item.blackCardId}}&nbsp;</div>
        {{#  } }}
        {{# }); }}
    </script>

    <script type="text/html" id="caseTypeTpl">
        {{# layui.each(d.reporteders, function(index, item){ }}
        {{#  if(item.caseType != ''){ }}
        <div class="layui-input-inline">{{item.caseType}}&nbsp;</div>
        {{#  } }}
        {{# }); }}
    </script>


    <script type="text/html" id="blackDepartmentTpl">
        {{# layui.each(d.reporteders, function(index, item){ }}
        {{#  if(item.blackDepartment == '未选择'){ }}
        <div class="layui-input-inline">无单位</div>
        {{#  } else { }}
        <div class="layui-input-inline">{{item.blackDepartment}}</div>
        {{#  } }}
        {{# }); }}
    </script>

    <script type="text/html" id="involvedUnitTpl">
        {{# layui.each(d.involvedUnit, function(index, item){ }}
            <div class="layui-input-inline">{{item}}</div>
        {{# }); }}
    </script>

    <script type="text/html" id="sendDepartmentTpl">
        {{#  if(d.sendDepartment != ''){ }}
            {{#  if(d.sendDepartment.value != -1){ }}
                {{#  if(d.sendDepartment.value != 0){ }}
                <div class="layui-input-inline">{{d.sendDepartment.name}}</div>
                {{#  } else { }}
                <div class="layui-input-inline">{{d.sendDepartmentMemo}}</div>
                {{#  } }}
            {{#  } }}
        {{#  } }}
    </script>

    <script type="text/html" id="reportFromTpl">
        {{#  if(d.reportFrom.value != -1){ }}
        <div class="layui-input-inline">{{d.reportFrom.name}}</div>
        {{#  } }}
    </script>

    <script type="text/html" id="levelTpl">
        {{#  if(d.level.value != -1){ }}
        <div class="layui-input-inline">{{d.level.name}}</div>
        {{#  } }}
    </script>

    <script type="text/html" id="conclusionTpl">
        {{#  if(d.conclusion.value != -1){ }}
        <div class="layui-input-inline">{{d.conclusion.name}}</div>
        {{#  } }}
    </script>

    <script type="text/html" id="fourShapesTpl">
        {{#  if(d.fourShapes.value != -1){ }}
        <div class="layui-input-inline">{{d.fourShapes.name}}</div>
        {{#  } }}
    </script>

    <script type="text/html" id="processResultTpl">
        {{#  if(d.processResult.value != -1){ }}
        <div class="layui-input-inline">{{d.processResult.name}}</div>
        {{#  } }}
    </script>

    <script type="text/html" id="issueTypeTpl">
        {{# layui.each(d.issueType, function(index, item){ }}
        {{#  if(d.issueType.length != 0){ }}
        <div class="layui-input-inline">{{item}}</div>
        {{#  } }}
        {{# }); }}
    </script>


    <script type="text/html" id="isSendTpl">
        {{#  if(d.isSend === '否'){ }}
        <span style="color: #ff4927;">{{ d.isSend }}</span>
        {{#  } else { }}
        <span style="color: #0084ff;">{{ d.isSend }}</span>
        {{#  } }}
    </script>

    <script type="text/html" id="isRepeatTpl">
        {{#  if(d.isRepeat === '不重复'){ }}
        {{ d.isRepeat }}
        {{#  } else { }}
        <span style="color: #ff4927;">{{ d.isRepeat }}</span>
        {{#  } }}
    </script>

    <script type="text/html" id="reportTypeTpl">
        {{#  if(d.reportType != '未选择'){ }}
            {{ d.reportType }}
        {{#  }  }}
    </script>

    <script type="text/html" id="reportStateTpl">
        {{#  if(d.reportState === '已移送，未反馈' || d.reportState === '退回完善'){ }}
        <span style="color: #F6AD55;">{{ d.reportState }}</span>
        {{#  } else if(d.reportState === '已反馈，待审核' || d.reportState === '申请查结') { }}
        <span style="color: #0084ff;">{{ d.reportState }}</span>
        {{#  } else if(d.reportState === '已完成') { }}
        <span style="color: #2ebd59;">{{ d.reportState }}</span>
        {{#  } else { }}
            {{ d.reportState }}
        {{#  } }}
    </script>

    <script type="text/html" id="progressTpl">
        {{#  if(d.progress === '查结'){ }}
        <span style="color: #2ebd59;">{{ d.progress }}</span>
        {{#  } else if((d.progress === '正在核查')) { }}
        <span style="color: #0084ff;">{{ d.progress }}</span>
        {{#  } else { }}
        <span style="color: #F6AD55;">{{ d.progress }}</span>
        {{#  } }}
    </script>

    <script type="text/html" id="toolbar">

        <button class="pear-btn pear-btn-primary pear-btn-md" style="cursor: default;"> 
            <i class="layui-icon layui-icon-console"></i> 数据表格
        </button>

        <!-- <button class="pear-btn pear-btn-success pear-btn-md" lay-event="uploadExcel"> 
            <i class="layui-icon layui-icon-upload-drag"></i> 导入数据 
        </button> -->

    </script>

    <script type="text/html" id="column-toolbar">
        <button class="pear-btn pear-btn-sm" lay-event="history">
            <span class="icon pear-icon" title="历史记录">&#xe6d9;</span>
        </button>
        <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit">
            <span class="icon pear-icon" title="编辑">&#xe6a3;</span>
        </button>
        <button class="pear-btn pear-btn-warming pear-btn-sm" lay-event="uploadFile">
            <span class="icon pear-icon" title="附件">&#xe6ab;</span>
        </button>
        <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove">
            <span class="icon pear-icon" title="删除">&#xe680;</span>
        </button>
    </script>

    <script src="../../js/jquery-3.4.1.min.js"></script>
    <script src="../../js/jquery.js"></script>
    <script src="../../component/layui/layui.js"></script>
    <script src="../../component/pear/pear.js"></script>

    <script>
        var options = layui.data('options').data
        // reportState "暂存" 变 ""， 不显示不给查, 对应暂存列表界面的搜索栏
        options.reportState[0].label = ""

        var userInfoData = layui.data('userInfo').item
        var locationParams = myUtils.GetRequest()
        // console.log("页面接收参数locationParams: ", locationParams)

        var reportVO = {
            "conclusion": null,
            "fourShapes": null,
            "involvedRegion": [
                {
                    "area": null,
                    "city": "厦门",
                    "province": "福建"
                }
            ],
            "isRepeat": null,
            "isSend": null,
            "issueType": null,
            "level": null,
            "no": null,
            "sendToId": null,
            "processResult": null,
            "progress": null,
            "reportFrom": null,
            "reportType": null,
            "reporteders": null,
            "reporter": null,
            "sendDepartment": null,
            "sendDepartmentMemo": null,
            "reportState": null,
            "reportCaseType": null,
        }

        // console.log(locationParams.type)
        if (locationParams.type != undefined) {
            reportVO['involvedRegion'] = [
                {
                    "area": null,
                    "city": null,
                    "province": null
                }
            ]
            if (locationParams.type == 'tempsave') {
                reportVO['reportState'] = -1
            } else if (locationParams.type == 'sendBack') {
                reportVO['reportState'] = 4
            } else if (locationParams.type == 'check') {
                reportVO['reportState'] = 5
            }
        }

        // console.log("reportVO reportState: ", reportVO['reportState'])
        layui.use(['table', 'form', 'laydate', 'laytpl', 'Api', 'upload', 'pca', 'opTable', 'request'], function () {
            var $ = layui.$,
                table = layui.table,
                form = layui.form,
                laytpl = layui.laytpl,
                laydate = layui.laydate,
                Api = layui.Api,
                pca = layui.pca,
                upload = layui.upload,
                request = layui.request,
                opTable = layui.opTable;

            initSearch()
            var ToolbarList = [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter']
            if (userInfoData.departmentCode == -2 && userInfoData.role == 0) {  // 仅杉哥部门可打印和导出
                ToolbarList = [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'exports', 'print']
            }
            var pageChoose = [10, 100]
            var myTable = table.render({
                elem: '#excel-table',
                id: 'excel-table',
                url: Api.listSearch,
                headers: {
                    'token': localStorage.token
                },
                parseData: function (res) { //res 即为原始返回的数据
                    if (res.errno != 0) {
                        layer.alert(res.errmsg, { icon: 2 }, function (index) {
                            layer.close(index);
                        });
                    }
                    pageChoose.pop()
                    pageChoose.push(res.data.total)
                    return {
                        "code": res.errno, //解析接口状态
                        "msg": res.errmsg, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.list //解析数据列表
                    };
                },
                where: {
                    reportVO: reportVO,
                    startTime: "2021-01-01",
                    endTime: myUtils.getToday(),
                    caseType: null
                },
                method: 'post',
                contentType: 'application/json',
                request: {
                    pageName: 'page_index', //页码的参数名称，默认：page
                    limitName: 'page_size'  //每页数据量的参数名，默认：limit
                },
                page: {
                    limit: 10,
                    limits: pageChoose,
                },
                loading: false,
                // skin: 'line',
                toolbar: '#toolbar',
                defaultToolbar: ToolbarList,  /* 调整数据表格右侧工具栏 */
                smartReloadModel: true,
                cols: [
                    [   // 一级表头
                        { sort: false, align: 'center', hide: false, type: 'numbers', fixed: 'left', title: '序号' },

                        { sort: true, align: 'center', hide: false, minWidth: 170, field: 'no', title: '受理编号' },
                        { sort: true, align: 'center', hide: false, minWidth: 100, field: 'reportCaseType', title: '涉案类别' },
                        { sort: true, align: 'center', hide: true, minWidth: 150, field: 'mailNo', title: '来电来信线索编号', },
                        { sort: true, align: 'center', hide: true, minWidth: 150, field: 'reportType', title: '线索来源', templet: '#reportTypeTpl' },
                        { sort: true, align: 'center', hide: true, minWidth: 150, field: 'reportFrom', title: '一手来源单位' },
                        { sort: true, align: 'center', hide: true, minWidth: 160, field: 'moreLetter', title: '还要来信反映' },
                        { sort: false, align: 'center', hide: true, minWidth: 200, field: 'involvedRegion', title: '涉及区域', templet: '#involvedRegionTpl' },
                        { sort: false, align: 'center', hide: false, minWidth: 100, field: 'name', title: '举报人姓名', templet: '<span>{{d.reporter.name}}</span>' },
                        { sort: false, align: 'center', hide: true, minWidth: 200, field: 'cardId', title: '身份证号', templet: '<span>{{d.reporter.cardId}}&nbsp;</span>' },
                        { sort: false, align: 'center', hide: true, minWidth: 120, field: 'phone', title: '联系方式', templet: '<span>{{d.reporter.phone}}</span>' },
                        { sort: false, align: 'center', hide: true, minWidth: 120, field: 'location', title: '住所地', templet: '<span>{{d.reporter.location}}</span>' },

                        { sort: false, align: 'center', hide: false, minWidth: 150, field: 'reporteders', title: '被举报人姓名', templet: '#blackNameTpl' },
                        { sort: false, align: 'center', hide: false, minWidth: 160, field: 'reporteders', title: '被举报人单位', templet: '#blackDepartmentTpl' },
                        { sort: true, align: 'center', hide: true, minWidth: 200, field: 'blackCardId', title: '被举报人身份证', templet: '#blackCardIdTpl' },
                        { sort: true, align: 'center', hide: false, minWidth: 120, field: 'question', title: '主要问题', },
                        { sort: true, align: 'center', hide: true, minWidth: 160, field: 'caseType', title: '被举报人涉案类别', templet: '#caseTypeTpl' },

                        { sort: false, align: 'center', hide: true, minWidth: 220, field: 'issueType', title: '顽瘴痼疾类别', templet: '#issueTypeTpl' },
                        { sort: false, align: 'center', hide: true, minWidth: 160, field: 'involvedUnit', title: '涉及单位', templet: '#involvedUnitTpl' },
                        { sort: true, align: 'center', hide: true, minWidth: 130, field: 'isVolunteered', title: '主动说明情况' },
                        { sort: true, align: 'center', hide: true, minWidth: 110, field: 'isSweepBlack', title: '扫黑除恶' },
                        { sort: false, align: 'center', hide: true, minWidth: 150, field: 'completeDataMemo', title: '数据完善备注', },

                        { sort: true, align: 'center', hide: true, minWidth: 110, field: 'isSend', title: '是否移送', templet: '#isSendTpl' },
                        { sort: true, align: 'center', hide: false, minWidth: 130, field: 'reportState', title: '线索状态', templet: '#reportStateTpl' },
                        { sort: true, align: 'center', hide: false, minWidth: 110, field: 'sendDepartment', title: '移送单位' },
                        { sort: true, align: 'center', hide: false, minWidth: 110, field: 'sendTime', title: '移交时间', },
                        { sort: true, align: 'center', hide: true, minWidth: 180, field: 'sendToId', title: '移送编号' },
                        { sort: true, align: 'center', hide: true, minWidth: 110, field: 'feedbackTimeLimit', title: '反馈时限', },
                        { sort: true, align: 'center', hide: true, minWidth: 110, field: 'feedbackTime', title: '反馈时间', },
                        { sort: true, align: 'center', hide: true, minWidth: 110, field: 'doneTimeLimit', title: '查结时限', },

                        { sort: true, align: 'center', hide: true, minWidth: 110, field: 'level', title: '核查等级' },
                        { sort: true, align: 'center', hide: false, minWidth: 110, field: 'progress', title: '核查进展', templet: '#progressTpl' },
                        { sort: true, align: 'center', hide: true, minWidth: 110, field: 'conclusion', title: '核查结论' },
                        { sort: true, align: 'center', hide: true, minWidth: 110, field: 'fourShapes', title: '四种形态' },
                        { sort: true, align: 'center', hide: true, minWidth: 110, field: 'processResult', title: '处理结果' },
                        { sort: false, align: 'center', hide: true, minWidth: 150, field: 'feedbackMemo', title: '核查反馈备注', },

                        { sort: true, align: 'center', hide: true, minWidth: 110, field: 'isRepeat', title: '是否重复', templet: '#isRepeatTpl' },
                        { sort: true, align: 'center', hide: true, minWidth: 110, field: 'enterer', title: '录入人', },
                        { sort: false, align: 'center', hide: false, minWidth: 180, title: '操作', fixed: 'right', toolbar: '#column-toolbar' }
                    ]
                ],
                // size: 'lg',
                done: function (res, curr, count) {
                    // dataAllCount = count
                    // currData = res.data
                    uploadRender()
                }
            });

            table.on('toolbar(excel-table)', function (obj) {
                if (obj.event === 'refresh') {
                    table.reload('excel-table');
                }
            });

            // 工具条点击事件
            table.on('toolbar', function (obj) {
                var data = obj.data;
                var event = obj.event;
                var self = this
                console.log("工具条点击...: ", event)
                if (event === 'addData') {
                    layer.open({
                        content: "../../view/excel/excel-add.html",
                        title: "新增数据",
                        area: ['90%', '95%'],
                        type: 2,
                        maxmin: true,
                        shadeClose: true
                    });
                } else if (event === 'refresh') {
                    table.reload('excel-table');
                } else if (event === 'uploadExcel') {
                    layer.msg('玩命开发中...');
                }
            });

            function uploadRender() {
                upload.render({ //允许上传的文件后缀
                    elem: '#uploadExcel',
                    url: Api.importData //改成您自己的上传接口
                    ,
                    accept: 'file' //普通文件
                    ,
                    field: 'excelFile',
                    exts: 'xlsx' //只允许上传压缩文件
                    ,
                    done: function (res) {
                        // console.log(res)
                        if (res.errno === 0) {
                            layer.msg("导入成功", {
                                icon: 1
                            })
                        } else {
                            layer.msg(res.errmsg, {
                                icon: 2
                            })
                        }
                    }
                });
            }


            // 行点击事件 重置密码
            table.on('tool', function (obj) {
                var data = obj.data;
                var event = obj.event;
                if (event === 'edit') {
                    if (userInfoData.departmentCode != -2) { // 子部门
                        let code = myUtils.getCodeFromName(options.reportState, data.reportState)
                        if (code != 3) { // 未查结前可修改
                            edit(data.id)
                        } else {
                            layer.alert('未查结前可修改！', { icon: 0 })
                        }
                    } else {
                        edit(data.id)
                    }
                } else if (event === 'uploadFile') {
                    // 上传附件
                    let code = myUtils.getCodeFromName(options.reportState, data.reportState)
                    attachPage(data.no, data.id, code)
                } else if (event === 'history') {
                    if (userInfoData.role != 0) {
                        // 弹窗无权限
                        // console.log("弹窗无权限")
                        layer.alert('对不起，您无此权限！', { icon: 4, })
                    } else {
                        seeHistory(data.id)
                    }
                } else if (event === 'remove') {
                    console.log("userInfoData: ", userInfoData)
                    if (userInfoData.role === 0 && userInfoData.username === 'shan') {
                        removeData(data.id, data.no)
                    } else {
                        // 弹窗无权限
                        layer.alert('对不起，您无此权限！', { icon: 4, })
                    }
                }
            });

            function removeData(id, no) {
                layer.confirm('确定删除该线索？', {
                    btn: ['取消', '确定'] //按钮
                }, function () {
                    layer.msg('已取消', { icon: 1 });
                }, function () {
                    layer.prompt({ title: '请输入该线索编号', formType: 0 }, function (pass, index) {
                        if ($.trim(pass) === $.trim(no)) {
                            let url = Api.report + '/' + id
                            let success = function (res) {
                                console.log("res: ", res)
                                if (res.errno == 0) {
                                    layer.close(index);
                                    layer.msg('已删除', { icon: 1 });
                                    table.reload('excel-table');
                                } else {
                                    layer.msg(res.errmsg, {
                                        icon: 2
                                    })
                                }
                            }
                            request.delete(url, {}, success)
                        } else {
                            layer.msg('编号输入错误！', { icon: 2 });
                        }
                    });
                });
            }

            function edit(id) {
                let editPageUrl = '../../view/excel/excel-edit.html?type=' + locationParams.type
                if (userInfoData.departmentCode != -2) {
                    editPageUrl = '../../view/excel/excel-edit-son.html'
                }
                let params = {}
                let url = Api.report + '/' + id
                var success = function (res) {
                    if (res.errno == 0) {
                        layui.data('reportInfo', { key: 'item', value: res.data });
                        layer.open({
                            content: encodeURI(editPageUrl),
                            title: "编辑",
                            area: ['90%', '95%'],
                            type: 2,
                            maxmin: true,
                            shadeClose: true,
                            end: function (res) {
                                layui.data('reportInfo', { key: 'item', remove: true });
                                // table.reload('excel-table');
                            }
                        });
                    }
                }
                request.get(url, params, success)
            }

            function attachPage(no, id, code) {
                var url = '../../view/nav/attachment.html?no=' + no + '&id=' + id + '&code=' + code
                layer.open({
                    type: 2,
                    closeBtn: 1,
                    title: '🕒 附件',
                    area: ['80%', '70%'],
                    content: encodeURI(url),
                    scrollbar: false,
                    maxmin: true,
                    shadeClose: true,
                    success: function () {

                    },
                    end: function () {
                        // table.reload('excel-table');
                    }
                });
            }

            function seeHistory(id) {
                var url = '../../view/excel/excel-history.html?id=' + id
                layer.open({
                    type: 2,
                    closeBtn: 1,
                    title: '📚 历史记录',
                    area: ['90%', '90%'],
                    content: encodeURI(url),
                    scrollbar: false,
                    maxmin: true,
                    shadeClose: true,
                    success: function () {

                    },
                    end: function () {
                        // table.reload('excel-table');
                    }
                });
            }

            form.on('submit(reset)', function (form) {
                initLaydate()
                return false;
            });

            form.on('select(reportFrom)', function (data) {
                // console.log('reportFrom val', data.value)
                if (data.value == "8") {
                    // 选到 【8 指导组】 才有 线索来源
                    $('#reportFromDIV').show()
                } else {
                    $('#reportFromDIV').hide()
                }
                form.render('select')
            });

            // 表格重载（筛选数据）
            form.on('submit(search)', function (form) {

                // console.log("form.field: ", JSON.stringify(form.field))
                var url = Api.listSearch + '?multiSources=' + form.field['multiSources']
                var params = updateParams(form.field)
                // reportVO = params
                // console.log("（筛选数据）url: ", JSON.stringify(url))
                // console.log("（筛选数据）params: ", JSON.stringify(params))
                // console.log("req json", JSON.stringify({
                //     reportVO: params,
                //     startTime: form.field.startTime,
                //     endTime: form.field.endTime
                // }))
                let caseType = form.field.caseType != "-1" ? form.field.caseType : null
                table.reload('excel-table', {
                    url: url,
                    where: {
                        reportVO: params,
                        startTime: form.field.startTime,
                        endTime: form.field.endTime,
                        caseType: parseInt(caseType)
                    },
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                });
                return false;
            });

            function updateParams(params) {

                // involvedRegion
                reportVO.involvedRegion[0].province = params["province"] === '全部' ? null : params["province"]
                reportVO.involvedRegion[0].city = params["city"] === '全部' ? null : params["city"]
                reportVO.involvedRegion[0].area = params["area"] === '全部' ? null : params["area"]
                // reporter name
                var reporter = {
                    "name": null,
                    "phone": null
                }
                reporter.name = params['name'] != '' ? $.trim(params['name']) : null
                reporter.phone = params['phone'] != '' ? $.trim(params['phone']) : null
                reportVO.reporter = reporter
                // blackName
                var reporteders = [{
                    "blackDepartment": null,
                    "name": null
                }]
                reporteders[0].name = params['blackName'] != '' ? $.trim(params['blackName']) : null
                reporteders[0].blackDepartment = params['blackDepartment'] != -1 ? parseInt(params['blackDepartment']) : null
                reportVO.reporteders = reporteders

                // 受理编号 | 移送编号
                reportVO.no = params['no'] != '' ? $.trim(params['no']) : null
                reportVO.sendToId = params['sendToId'] != '' ? $.trim(params['sendToId']) : null

                //other
                reportVO.isRepeat = params['isRepeat'] != -1 ? parseInt(params['isRepeat']) : null
                reportVO.reportType = params['reportType'] != -1 ? parseInt(params['reportType']) : null
                reportVO.reportFrom = params['reportFrom'] != -1 ? parseInt(params['reportFrom']) : null
                reportVO.isSend = params['isSend'] != -1 ? parseInt(params['isSend']) : null
                reportVO.sendDepartment = params['sendDepartment'] != -1 ? parseInt(params['sendDepartment']) : null
                reportVO.progress = params['progress'] != -1 ? parseInt(params['progress']) : null
                reportVO.level = params['level'] != -1 ? parseInt(params['level']) : null
                reportVO.conclusion = params['conclusion'] != -1 ? parseInt(params['conclusion']) : null
                reportVO.fourShapes = params['fourShapes'] != -1 ? parseInt(params['fourShapes']) : null
                reportVO.processResult = params['processResult'] != -1 ? parseInt(params['processResult']) : null
                reportVO.issueType = params['issueType'] != -1 ? [parseInt(params['issueType'])] : null
                reportVO.reportCaseType = params['reportCaseType'] != -1 ? parseInt(params['reportCaseType']) : null
                reportVO.reportState = params['reportState'] != -1 ? parseInt(params['reportState']) : null
                if (locationParams.type == 'tempsave') reportVO.reportState = -1

                return reportVO
            }

            function initSearch() {
                var getFormTpl = formHtml.innerHTML,
                    formView = document.getElementById('formView');
                // console.log("initForm options: ", options)
                laytpl(getFormTpl).render({
                    options: options,
                    pageType: locationParams.type
                }, function (html) {
                    formView.innerHTML = html;
                    initOthers()
                });
            }

            function initOthers() {
                // 初始化地区、时间选择器
                // involvedRegion
                let province = reportVO.involvedRegion[0].province === null ? '全部' : reportVO.involvedRegion[0].province
                let city = reportVO.involvedRegion[0].city === null ? '全部' : reportVO.involvedRegion[0].city
                let area = reportVO.involvedRegion[0].area === null ? '全部' : reportVO.involvedRegion[0].area
                pca.init('select[name=province]', 'select[name=city]', 'select[name=area]', province, city, area);
                initLaydate()
                $('#reportFromDIV').hide()
            }

            function initLaydate() {
                laydate.render({
                    elem: '#startTime',
                    format: 'yyyy-MM-dd',
                    value: '2021-01-01',
                    min: '2013-01-01',
                    max: myUtils.getToday(),
                    trigger: 'click'
                });
                laydate.render({
                    elem: '#endTime',
                    format: 'yyyy-MM-dd',
                    value: myUtils.getToday(),
                    min: '2013-01-01',
                    max: myUtils.getToday(),
                    trigger: 'click'
                });
            }

            // filter筛选列全选
            table.on('toolbar()', function (obj) {
                var config = obj.config;
                var btnElem = $(this);
                var tableId = config.id;
                var tableView = config.elem.next();
                switch (obj.event) {
                    case 'LAYTABLE_COLS':
                        // 给筛选列添加全选还有反选的功能
                        var panelElem = btnElem.find('.layui-table-tool-panel');
                        var checkboxElem = panelElem.find('[lay-filter="LAY_TABLE_TOOL_COLS"]');
                        var checkboxCheckedElem = panelElem.find('[lay-filter="LAY_TABLE_TOOL_COLS"]:checked');
                        $('<li class="layui-form" lay-filter="LAY_TABLE_TOOL_COLS_FORM">' +
                            '<input type="checkbox" lay-skin="primary" lay-filter="LAY_TABLE_TOOL_COLS_ALL" '
                            + ((checkboxElem.length === checkboxCheckedElem.length) ? 'checked' : '') + ' title="全选">' +
                            '<span class="LAY_TABLE_TOOL_COLS_Invert_Selection">反选</span></li>')
                            .insertBefore(panelElem.find('li').first())
                            .on('click', '.LAY_TABLE_TOOL_COLS_Invert_Selection', function (event) {
                                layui.stope(event);
                                // 反选逻辑
                                panelElem.find('[lay-filter="LAY_TABLE_TOOL_COLS"]+').click();
                            });
                        form.render('checkbox', 'LAY_TABLE_TOOL_COLS_FORM');
                        break;
                }
            });

            // 监听筛选列panel中的全选
            form.on('checkbox(LAY_TABLE_TOOL_COLS_ALL)', function (obj) {
                $(obj.elem).closest('ul')
                    .find('[lay-filter="LAY_TABLE_TOOL_COLS"]' + (obj.elem.checked ? ':not(:checked)' : ':checked') + '+').click();
            });

            // 监听筛选列panel中的单个记录的change
            $(document).on('change', 'input[lay-filter="LAY_TABLE_TOOL_COLS"]', function (event) {
                var elemCurr = $(this);
                // 筛选列单个点击的时候同步全选的状态
                $('input[lay-filter="LAY_TABLE_TOOL_COLS_ALL"]')
                    .prop('checked',
                        elemCurr.prop('checked') ? (!$('input[lay-filter="LAY_TABLE_TOOL_COLS"]').not(':checked').length) : false);
                form.render('checkbox', 'LAY_TABLE_TOOL_COLS_FORM');
            });
        });
    </script>
</body>

</html>